﻿package _fla
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;

    dynamic public class MainTimeline extends MovieClip
    {
        public var News:news;
        public var myXML:XML;
        public var url_source:String;
        public var arr_time:Array;
        public var arr_mess:Array;
        public var loader:Object;
        public var counter:Number;
        public var myTimer:Timer;

        public function MainTimeline()
        {
            addFrameScript(0, this.frame1);
			News.addEventListener(MouseEvent.CLICK,navFaceBook);
			News.buttonMode = true;
            return;
        }// end function
		private function navFaceBook(e:MouseEvent):void{
			navigateToURL(new URLRequest("https://www.facebook.com/CaptainsOfLives"));
		}
        public function xmlLoaded(event:Event) : void
        {
            var _loc_2:XML = null;
            var _loc_3:* = undefined;
            var _loc_4:* = undefined;
            var _loc_5:* = undefined;
            var _loc_6:* = undefined;
            var _loc_7:* = undefined;
            this.loader.removeEventListener(Event.COMPLETE, this.xmlLoaded);
            if (event.target as URLLoader != null)
            {
                this.myXML = new XML(event.target.data);
                for each (_loc_2 in this.myXML.article)
                {
                    
                    _loc_3 = new Date(_loc_2.createdate * 1000);
                    _loc_4 = _loc_3.getDate().toString();
                    _loc_5 = "";
                    if (++_loc_4 < 10)
                    {
                        _loc_5 = _loc_5 + ("0" + ++_loc_4 + "/");
                    }
                    else
                    {
                        _loc_5 = _loc_5 + (_loc_4 + "/");
                    }
                    _loc_6 = _loc_3.getMonth().toString();
                    if (++_loc_6 < 10)
                    {
                        _loc_5 = _loc_5 + ("0" + ++_loc_6 + "/");
                    }
                    else
                    {
                        _loc_5 = _loc_5 + (_loc_6 + "/");
                    }
                    _loc_7 = _loc_3.getFullYear().toString();
                    _loc_5 = _loc_5 + (_loc_7 + ".");
                    this.arr_time.push(_loc_5);
                    this.arr_mess.push(_loc_2.message);
                    this.News.datetime.text = this.arr_time[0];
                    this.News.mess.text = this.arr_mess[0];
                }
            }
            return;
        }// end function

        public function timerListener(event:TimerEvent) : void
        {
            var _loc_3:Object = this;
            var _loc_4:* = this.counter + 1;
            _loc_3.counter = _loc_4;
            if (this.counter >= 5)
            {
                this.counter = 0;
            }
            var _loc_2:* = this.sub_string(this.arr_mess[this.counter], 100);
            this.News.datetime.text = this.arr_time[this.counter];
            this.News.mess.text = _loc_2;
            return;
        }// end function

        public function sub_string(param1:String, param2:Number) : String
        {
            var _loc_3:* = new Array();
            var _loc_4:* = "";
            param1.split("  ").join(" ");
            _loc_3 = param1.split(" ");
            var _loc_5:Number = 0;
            while (_loc_5 < param2)
            {
                
                if (_loc_3[_loc_5])
                {
                    _loc_4 = _loc_4 + (_loc_3[_loc_5] + " ");
                }
                _loc_5 = _loc_5 + 1;
            }
            return _loc_4;
        }// end function

        function frame1()
        {
            this.url_source = "facebook.xml";
            this.arr_time = new Array();
            this.arr_mess = new Array();
            this.loader = new URLLoader();
            this.counter = 0;
            this.myTimer = new Timer(5000);
            this.loader.load(new URLRequest(this.url_source));
            this.loader.addEventListener(Event.COMPLETE, this.xmlLoaded);
            this.myTimer.addEventListener(TimerEvent.TIMER, this.timerListener);
            this.myTimer.start();
            return;
        }// end function

    }
}
